<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>5- 常见的几何体</title>
</head>

<body>

</body>
<script type="importmap">
    {
        "imports": {
            "three": "./build/three.module.js",
            "three/addons/": "./examples/jsm/"
        }
    }
</script>
<script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    import Stats from 'three/addons/libs/stats.module.js';

    const width = window.innerWidth;
    const height = window.innerHeight;

    // 创建场景 相机 渲染器 
    const scene = new THREE.Scene()
    const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000);
    const renderer = new THREE.WebGLRenderer()
    renderer.setSize(width, height)
    camera.position.set(400, 400, 400);
    camera.lookAt(0, 0, 0);

    // 添加辅助坐标轴
    const axesHelper = new THREE.AxesHelper(150);
    scene.add(axesHelper)

    // 创建几何体
    // const geometry = new THREE.SphereGeometry(50);  // 球体
    // const geometry = new THREE.CylinderGeometry(50, 50, 100); // 圆柱体
    // const geometry = new THREE.PlaneGeometry(100, 50); // 矩形平面
    const geometry = new THREE.CircleGeometry(50); // 圆型平面
    const material = new THREE.MeshLambertMaterial({
        color: 0x00ffff,
        transparent: true,
        opacity: 0.5
    })
    const mesh = new THREE.Mesh(geometry, material)
    mesh.position.set(0, 0, 0);

    // 平行光
    const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
    directionalLight.position.set(100, 100, 100);
    directionalLight.target = mesh;
    scene.add(directionalLight);
    // 辅助光源
    const dirLightHelper = new THREE.DirectionalLightHelper(directionalLight, 10);
    scene.add(dirLightHelper);


    // 轨道控制器
    const controls = new OrbitControls(camera, renderer.domElement);
    controls.addEventListener('change', function () {
        renderer.render(scene, camera); //执行渲染操作
    });//监听鼠标、键盘事件

    // 添加
    scene.add(mesh)
    document.body.appendChild(renderer.domElement);
    renderer.render(scene, camera)

</script>

</html>